//
//  UIDevice+Extension.swift
//  LiveTrivia
//
//  Created by Gesen on 2017/11/17.
//  Copyright © 2017年 LiveTrivia. All rights reserved.
//

import UIKit
import AdSupport
import SystemConfiguration.CaptiveNetwork

extension UIDevice {
    
    static var osVersion: String {
        return ProcessInfo.processInfo.operatingSystemVersionString
    }
    
    static var IDFA: String? {
        return ASIdentifierManager.shared().isAdvertisingTrackingEnabled ?
            ASIdentifierManager.shared().advertisingIdentifier.uuidString : nil
    }
    
    var ssid: String? {
        guard let cfa: NSArray = CNCopySupportedInterfaces() else { return nil }
        for x in cfa {
            if let dict = CFBridgingRetain(CNCopyCurrentNetworkInfo(x as! CFString)), let ssid = dict["SSID"] as? String {
                return ssid
            }
        }
        return nil
    }
    
    var bssid: String? {
        guard let cfa: NSArray = CNCopySupportedInterfaces() else { return nil }
        for x in cfa {
            if let dict = CFBridgingRetain(CNCopyCurrentNetworkInfo(x as! CFString)), let bssid = dict["BSSID"] as? String {
                return bssid
            }
        }
        return nil
    }
    
}
